from threading import RLock


class RemoteSession:
    def __init__(self):
        self._lock = RLock()
        self._session_map = {}

    def get_sid(self, addr):
        self._lock.acquire()
        sid = self._session_map.get(addr)
        self._lock.release()
        return sid

    def update(self, addr, sid):
        self._lock.acquire()
        self._session_map.update({
            addr: sid
        })
        self._lock.release()

    def remove(self, addr):
        self._lock.acquire()
        self._session_map.pop(addr)
        self._lock.release()


remote_session_map = RemoteSession()
